# #字符串的定义
# #单引号，双引号，三引号
# #原始字符串raw
# s = r"abc \n 123"
# s1 = "abc'd'"
# s2 = 'abc"d"'
# s3 = "\a"
# print(s,s1,s2,s3)
#
# #转义字符
# # \n \r \\ \" \' \t
#
# #切片
# my_str = "abc ddddd 123"
# print(my_str[0:5])

############################常用方法
#判断系列  is系列
str1 = "this Is Sanchuang"
str2 = "123四五六"
str3 = "Hello World"
str4 = "HELLO WORLD"
str5 = "sanchuang"

print("判断str2数字:",str2.isdigit())
print("判断str2数字:",str2.isnumeric())
print("判断字母：",str1.isalpha())
print("判断字母:",str5.isalpha())
print("判断是否为title格式:", str1.istitle())
print("判断是否为title格式:", str3.istitle())
print("判断是否全为大写：",str4.isupper())
print("判断是否以this开头：",str1.startswith("this"))
print("判断是否以g结尾:",str5.endswith("g"))

####查找统计类
#长度
print("长度:",len(str1))
print("查看i出现的次数:",str1.count("i"))
#查找L第一次出现的位置，没有找到就抛出异常
print("查看L第一次出现的位置:",str4.index("L"))
#没有找到返回-1
print("查找L第一次出现的位置:",str3.find("L"))

####转换类
msg = "%%welcom to Sanchuang"
print("大写：",msg.upper())
print("小写；",msg.lower())
print("标题格式:", msg.title())

#指定分隔符
#split指定分割符，得到字符串列表
print("切割:","root:x:root:122".split(':'))

lst1 = ["a", "l", "i", "c", "e"]
print("拼接：", "".join(lst1))

msg2 = "a%eee%ddd%f"
print("#".join(msg2.split('%')))
print("替换:",msg2.replace("%","#"))

print("大小写互换：",msg.swapcase())
print("0填充", msg.zfill(40))

#输出（左，右，中对齐）
print(msg.center(50,'#'))
print(msg.ljust(50,"#"))
print(msg.rjust(50,"#"))

#去除首位字符
print(msg.strip("%"))

